﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using ERCS.Model;


namespace ERCS.ViewModel.Patients.ReportVMs
{
    public partial class ReportListVM : BasePagedListVM<Report, ReportSearcher>
    {
        public ReportListVM()
        {
            DetailGridPrix = "Entity.Reports";

        }

        protected override List<GridAction> InitGridAction()
        {
            if (SearcherMode == ListVMSearchModeEnum.MasterDetail)
            {
                return new List<GridAction>();
            }
            else
            {
                return new List<GridAction>
            {
                this.MakeStandardAction("Report", GridActionStandardTypesEnum.AddRow, "新建","", dialogWidth: 800),
                this.MakeStandardAction("Report", GridActionStandardTypesEnum.RemoveRow, "删除","", dialogWidth: 800),
            };
            }
        }

        protected override IEnumerable<IGridColumn<Report>> InitGridHeader()
        {
            if (SearcherMode == ListVMSearchModeEnum.MasterDetail)
            {
                return new List<GridColumn<Report>>
                {
                    this.MakeGridHeader(x => x.Temprature),
                    this.MakeGridHeader(x => x.Remark),
                    this.MakeGridHeader(x => x.PatientName_view),
                };
            }
            else
            {
                return new List<GridColumn<Report>>{
                    this.MakeGridHeader(x => x.Temprature).SetEditType(EditTypeEnum.TextBox),
                    this.MakeGridHeader(x => x.Remark).SetEditType(EditTypeEnum.TextBox),
                    this.MakeGridHeaderAction(width: 200)
                };
            }
        }

        public override IOrderedQueryable<Report> GetSearchQuery()
        {
            var query = DC.Set<Report>()
                .CheckEqual(Searcher.PatientID, x=>x.PatientID)
                .Select(x => new Report
                {
				    ID = x.ID,
                    Temprature = x.Temprature,
                    Remark = x.Remark,
                    PatientName_view = x.Patient.PatientName,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

}
